mod animation;
mod mover;
mod baton;
mod animover;


use ggez::{Context, GameResult, GameError, graphics};

pub struct State{
    movers: Vec<Box<dyn animation::Animation>>,
}

impl State{
    pub fn new(_ctx: &mut Context) -> State {
        let mut movers: Vec<Box<dyn animation::Animation>> = vec![];

        for _i in 0..10 {
            let mover = baton::Baton::new();
            movers.push(Box::new(mover));

        }

        State{ movers}
    }
}

impl ggez::event::EventHandler<GameError> for State {
    fn update(&mut self, ctx: &mut Context) -> GameResult {
        for mover in &mut self.movers {
            mover.update(ctx);
        }
        Ok(())
    }
    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let mut canvas = graphics::Canvas::from_frame(ctx, graphics::Color::WHITE);

        for mover in &mut self.movers {
            mover.display(ctx, &mut canvas);
        }
        canvas.finish(ctx)?;
        Ok(())
    }
}